<template>
  <view>
    <view class="cu-list menu">
      <view class="solids-bottom padding-xs flex align-center" @tap="goToUrl('../userinfo/userinfo')">
        <view class="padding text-xxl">
          <text class="cuIcon cuIcon-lock text-pink"></text>
        </view>
        <view class="flex-sub text-left">
          <view class="text-bold">
            <text>修改密码</text>
          </view>
          <view class="text-grey text-sm">建议每隔一个月修改一次密码</view>
        </view>
        <view class="action">
          <text class="cuIcon cuIcon-right text-grey"></text>
        </view>
      </view>
      <view class="solids-bottom padding-xs flex align-center" @tap="showModal" data-target="DialogModal1">
        <view class="padding text-xxl">
          <text class="cuIcon cuIcon-roundclose text-orange"></text>
        </view>
        <view class="flex-sub text-left">
          <view class="text-bold">
            <text>注销账户</text>
          </view>
          <view class="text-grey text-sm">删除所有数据，永久注销</view>
        </view>
        <view class="action">
          <text class="cuIcon cuIcon-right text-grey"></text>
        </view>
      </view>
    </view>
    <view class="cu-modal" :class="modalName == 'DialogModal1' ? 'show' : ''">
      <view class="cu-dialog">
        <view class="cu-bar bg-white justify-end">
          <view class="content">注销提示</view>
          <view class="action" @tap="hideModal">
            <text class="cuIcon-close text-red"></text>
          </view>
        </view>
        <view class="padding-xl">注销账户后，信息数据将永久删除</view>
        <view class="cu-bar bg-white justify-end">
          <view class="action">
            <button class="cu-btn line-green text-green" @tap="hideModal">取消</button>
            <button class="cu-btn bg-green margin-left" @tap="deluser">确定</button>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      modalName: null
    };
  },
  methods: {
    goToUrl(e) {
      uni.navigateTo({
        url: e
      });
    },
    showModal(e) {
      this.modalName = e.currentTarget.dataset.target;
    },
    hideModal(e) {
      this.modalName = null;
    },
    deluser() {
      var that = this;
      uni.request({
        url: that.app.apiHost + '/deluser',
        method: 'POST',
        header: { Authorization: 'bearer ' + that.app.getAuthCode() },
        success: (res) => {
          console.log(res.data);
          if (res.data.code == -1) {
            that.app.showMsg('请登陆后再操作!', '../login/login');
          }
          if (res.data.code == 0) {
            setTimeout(function () {
              that.app.showMsg('删除账户成功!', '/');
            }, 1500);
          } else {
            that.app.showMsg(res.data.msg);
          }
        },
        fail(res) {
          console.log(res);
        }
      });
    }
  }
};
</script>

<style></style>
